<template>
  <div class="search-bar">
    <el-form :inline="true" :model="formItem" class="form-filter" size="mini">
      <el-form-item>
        <TreeSelect
          v-model="formItem.s_orgCode"
          :multiple="false"
          :options="availableOganizations"
          placeholder="请选择所属部门"
          @input="inputOrg"
        />
      </el-form-item>
      <el-form-item>
        <el-button plain icon="el-icon-search" @click="search" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { userTree as tree } from '@neu/auth-ui/api/organization'
import TreeSelect from '@neu/biz-core/components/TreeSelect'
// 定义一个查询表单原始项
const formItem = {
  s_name: '',
  s_orgCode: null,
  s_isUserOrg: true
}

export default {
  name: 'ShiftTableFilter',
  components: {
    TreeSelect
  },
  data() {
    return {
      formItem: {
        ...formItem
      },
      availableOganizations: []
    }
  },
  created() {
    tree().then(response => {
      this.availableOganizations = [...response.data]
    })
  },
  methods: {
    // 查询按钮点击事件处理
    search: function() {
      this.$parent.filter(this.formItem)
    },
    // 重置按钮点击事件处理
    reset: function() {
      this.formItem = {
        ...formItem
      }
      this.search()
    },
    onChange: function(val) {
      this.$parent.onResize()
    },
    inputOrg: function(value) {
      this.$parent.filter(this.formItem)
    }
  }
}
</script>
